

#include <sys/cdefs.h>

#if !defined(_KERNEL) && !defined(_STANDALONE)
#include <assert.h>
#include <string.h>
#else
#include <lib/libkern/libkern.h>
#endif

int
strncmp(const char *s1, const char *s2, size_t n)
{

	_DIAGASSERT(s1 != NULL);
	_DIAGASSERT(s2 != NULL);

	if (n == 0)
		return (0);
	do {
		if (*s1 != *s2++)
			return (*(const unsigned char *)s1 -
			    *(const unsigned char *)--s2);
		if (*s1++ == 0)
			break;
	} while (--n != 0);
	return (0);
}
